/**
 * 参数设置管理初始化
 */
var SuperPartnerActive = {
    id: "SuperPartnerActiveTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
SuperPartnerActive.initColumn = function () {
    var columns = [
        {field: 'selectItem', checkbox: true},
        {title: '序号', field: 'id', align: 'center', valign: 'middle',width:'50px'},
        {title: '激活码', field: 'activecode', align: 'center', valign: 'middle'},
        {title: '生成时间', field: 'appendtime', align: 'center',sortable: true, valign: 'middle'},
        {title: '手机号码', field: 'phone', align: 'center', valign: 'middle'},
        {title: '来源社区群名称', field: 'origin', align: 'center', valign: 'middle'},
        {title: '群主手机号码', field: 'ghphone', align: 'center', valign: 'middle'},
        {title: '短信发送状态', field: 'sendStatus', align: 'center', valign: 'middle'}
      ]
    return columns;
};

/**
 * 检查是否选中
 */
SuperPartnerActive.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        SuperPartnerActive.seItem = selected;
        return true;
    }
};

/**
 * 发送短信通知
 */
SuperPartnerActive.sendmsg = function () {
    if(this.check()) {
        //提交信息
        var ajax = new $ax(Feng.ctxPath + "/superPartnerActive/sendmsg", function (data) {
            Feng.success("发送成功!");
            window.SuperPartnerActive.table.refresh();
        }, function (data) {
            Feng.error("发送失败!" + data.responseJSON.message + "!");
        });
        ajax.set(SuperPartnerActive.seItem);
        ajax.start();
    }

};
/**
 * 批量导入
 */
SuperPartnerActive.upload = function () {

    // $("#fileupload").submit(function() {
    //     Feng.success("上传成功");
    //     window.SuperPartnerActive.table.refresh();
    // });
    var formFile = new FormData();
    var fileObj = document.getElementById("jobData").files[0];
    formFile.append("file", fileObj);

    var data = formFile;
    $.ajax({
        type: "POST",
        url: "/superPartnerActive/upload",
       // enctype: 'multipart/form-data',
        data: data,
        dataType: "json",
        contentType: false, //必须
        processData: false,//用于对data参数进行序列化处理 这里必须false
        cache: false,//上传文件无需缓存
        success: function (data) {
            if(data.code == 200){
                if(data.data.failuer == ""){
                    var msg = data.msg + "," + "成功插入" + data.data.succsscount;
                }else{
                    var msg =  data.msg + ",成功插入" + data.data.succsscount + ",插入失败" + data.data.failuer;
                }
                alert(msg);
                window.SuperPartnerActive.table.refresh();
            }else{
                alert(data.msg);
            }

        }
    });
};
/**
 * 删除参数设置
 */
SuperPartnerActive.delete = function () {
    if (this.check()) {
        arr = this.seItem;
        console.log(arr);
        var arr1 = new Array();
        for(var i=0;i< arr.length;i++){
            if(arr[i].status == 2){
                Feng.success("只能选择发送失败的记录删除!");
                return false;
            }else{
                arr1.push(arr[i].id);

            }
        }
        var ajax = new $ax(Feng.ctxPath + "/superPartnerActive/del", function (data) {
            Feng.success("删除成功!");
            SuperPartnerActive.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("id",arr1);
        ajax.start();
    }
};

/**
 * 查询参数设置列表
 */
SuperPartnerActive.search = function () {
    var queryData = {};

    queryData['phone'] = $("#phone").val();
    queryData['status'] = $("#status").val();

    SuperPartnerActive.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = SuperPartnerActive.initColumn();
    var table = new BSTable(SuperPartnerActive.id, "/superPartnerActive/list", defaultColunms);
    table.setPaginationType("client");
    SuperPartnerActive.table = table.init();
});
